package com.quanyue.haircut.controller;

import com.fasterxml.jackson.core.type.TypeReference;
import com.quanyue.auto.cache.core.CacheService;
import com.quanyue.haircut.domain.constant.CacheConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.Map;

@RestController
@Profile("prod")
public class HomeController {
    @Autowired
    private CacheService cacheService;

    @GetMapping(value = {"/", "/home/**", "/order"})
    public ModelAndView home(HttpServletRequest request) {
        Type type = new TypeReference <Map <String, String>>() {
        }.getType();
        Map <String, String> map = cacheService.get(CacheConstants.ATTRIBUTES_CACHE.name(), type);
        return new ModelAndView("index", map)
                .addObject("title",  "鼎骋美业");
    }
}
